/*
@hehung
2023-2-8
转载请注明出处，版权由@hehung所有
email: 1398660197@qq.com
wechat: hehung95
*/

#include "hal_data.h"
#include "app_hw_i2c.h"

/* sci3 i2c */
i2c_master_event_t sci3_i2c_event = I2C_MASTER_EVENT_ABORTED;
i2c_master_event_t sci2_i2c_event = I2C_MASTER_EVENT_ABORTED;

/* Initialize for I2c driver */
void I2c_Init(void)
{
	fsp_err_t err;
	
	// initialize the sci3 i2c
	// scl - P408
	// sda - P409
	err = R_SCI_I2C_Open(&g_sci3_i2c_ctrl, &g_sci3_i2c_cfg);
	assert(FSP_SUCCESS == err);

    // initialize the sci2 i2c
	// scl - P301
	// sda - P302
	err = R_SCI_I2C_Open(&g_sci2_i2c_ctrl, &g_sci2_i2c_cfg);
	assert(FSP_SUCCESS == err);
}

/* SCI3 I2C interrupt callback */
void sci3_i2c_master_callback(i2c_master_callback_args_t *p_args)
{
    sci3_i2c_event = I2C_MASTER_EVENT_ABORTED;
	
    if (NULL != p_args)
    {
        /* capture callback event for validating the i2c transfer event*/
        sci3_i2c_event = p_args->event;
    }
}

/* SCI1 I2C interrupt callback */
void sci2_i2c_master_callback(i2c_master_callback_args_t *p_args)
{
    sci2_i2c_event = I2C_MASTER_EVENT_ABORTED;
	
    if (NULL != p_args)
    {
        /* capture callback event for validating the i2c transfer event*/
        sci2_i2c_event = p_args->event;
    }
}
